package 面向对象高级.static关键字;

public class Employee {
    private static int total;
    static String company;
    private int id;
    private String name;

    public Employee() {
        total++;
        id=total;
    }

    public Employee(String name) {
        this();
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static int getTotal(){
        return total;
    }

    public static void setTotal(int total){
        Employee.total=total;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "company = " + company +
                ",id=" + id +
                ", name='" + name + '\'' +
                '}';
    }

    static class EmployeeTest{
        public static void main(String[] args) {
            //得到静态变量
            System.out.println(Employee.getTotal());

            Employee employee1 = new Employee("张三");
            Employee employee2 = new Employee("李四");
            System.out.println(employee1);
            System.out.println(employee2);
            System.out.println(Employee.getTotal());

            Employee.company="牛肉面";
            System.out.println(employee1);
            System.out.println(employee2);

            //权限修饰符允许，也能进行赋值，但是建议不要通过这种方式
            employee1.company="红烧牛肉面";

            System.out.println(employee1);
            System.out.println(employee2);

            //调用Chinese中的静态方法     调用静态方法时，就推荐这种写法
            Chinese.showPrint();
        }
    }
}
